package com.stage;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpSession;

import com.back.business.ActivityTableServiceImpl;
import com.back.business.IActivityTableService;
import com.back.business.ISchoolPhotoService;
import com.back.business.SchoolPhotoServiceImpl;
import com.base.web.BaseAction;
import com.domain.ActivityTable;
import com.domain.SchoolPhoto;
import com.opensymphony.xwork2.ActionContext;
import com.util.comm.RequestUtil;

public class Stageweb extends BaseAction {

	private IActivityTableService activityService;
	private ISchoolPhotoService schoolService;

	public Stageweb() {
		activityService = new ActivityTableServiceImpl();
		schoolService = new SchoolPhotoServiceImpl();
	}

	/**
	 * 前台获取 晴天介绍 author:lixiaomou time:2012.04.22 20:48
	 */
	public String information() {
		Map<String, String> parameMap = new HashMap<String, String>();
		HttpSession session = request.getSession();
		String lanType = "1";
		if (null != session.getAttribute("lanType")) {
			lanType = (String) session.getAttribute("lanType");
		}
		parameMap.put("lanType", lanType);
		parameMap.put("page", "1");
		parameMap.put("limit", "6");
		ActionContext context = ActionContext.getContext();
		if ("2".equals(lanType)) {
			ResourceBundle boundle = ResourceBundle.getBundle("globalMessage",
					Locale.US);
			Locale local = Locale.US;
			context.setLocale(local);
		}
		parameMap.put("type", "2");
		// 晴天新闻
		List<ActivityTable> newlist = activityService
				.findByActivityList(parameMap);
		context.put("activitylist", newlist);
		// 晴天足迹
		parameMap.remove("type");
		parameMap.put("type", "3");
		parameMap.put("rows", "7");
		List<SchoolPhoto> footlist = schoolService.findByParameMap(parameMap);
		/*
		 * List<ActivityTable> footlist = activityService
		 * .findByActivityList(parameMap);
		 */
		context.put("footlist", footlist);
		parameMap.remove("rows");
		parameMap.remove("type");
		// 晴天介绍
		parameMap.put("type", "1");
		List<ActivityTable> introducelist = activityService
				.findByActivityList(parameMap);
		context.put("introducelist", introducelist);
		return "index";
	}

	public String getInformation() {
		Map<String, String> parameMap = new HashMap<String, String>();
		HttpSession session = request.getSession();
		String lanType = "1";
		if (null != session.getAttribute("lanType")) {
			lanType = (String) session.getAttribute("lanType");
		}
		parameMap.put("lanType", lanType);
		String type = RequestUtil.getParam(request, "type", "1");
		ActionContext context = ActionContext.getContext();
		if ("2".equals(lanType)) {
			ResourceBundle boundle = ResourceBundle.getBundle("globalMessage",
					Locale.US);
			Locale local = Locale.US;
			context.setLocale(local);
		}

		parameMap.put("type", type);
		List<ActivityTable> introducelist = activityService
				.findByActivityList(parameMap);
		ActivityTable activetyTable = null;
		if (introducelist != null && !introducelist.isEmpty()) {
			activetyTable = introducelist.get(0);
		}
		context.put("actity", activetyTable);
		return "introduce";
	}

	public String getNews() {

		Map<String, String> parameMap = new HashMap<String, String>();
		HttpSession session = request.getSession();
		String lanType = "1";
		if (null != session.getAttribute("lanType")) {
			lanType = (String) session.getAttribute("lanType");
		}
		String type = RequestUtil.getParam(request, "type", "1");
		parameMap.put("lanType", lanType);
		/*
		 * parameMap.put("page", "1"); parameMap.put("limit", "10");
		 */
		ActionContext context = ActionContext.getContext();
		if ("2".equals(lanType)) {
			ResourceBundle boundle = ResourceBundle.getBundle("globalMessage",
					Locale.US);
			Locale local = Locale.US;
			context.setLocale(local);
		}
		// 晴天新闻
		// parameMap.remove("type");
		// parameMap.put("type","2");
		if ("3".equals(type)) {
			List<SchoolPhoto> introducelist = schoolService
					.findBySchoolList(parameMap);
			context.put("newList", introducelist);
			context.put("type", type);
		} else {
			parameMap.put("type", type);
			List<ActivityTable> introducelist = activityService
					.findByActivityList(parameMap);
			context.put("newList", introducelist);
			context.put("type", type);
		}
		return "show";
	}

	public String getDetail() {

		String id = RequestUtil.getParam(request, "id", "0");
		HttpSession session = request.getSession();
		String lanType = "1";
		if (null != session.getAttribute("lanType")) {
			lanType = (String) session.getAttribute("lanType");
		}
		ActionContext context = ActionContext.getContext();
		Map<String, String> parameMap = new HashMap<String, String>();
		if ("2".equals(lanType)) {
			ResourceBundle boundle = ResourceBundle.getBundle("globalMessage",
					Locale.US);
			Locale local = Locale.US;
			context.setLocale(local);
		}
		parameMap.put("lanType", lanType);
		parameMap.put("id", id);
		List<ActivityTable> detailList = activityService
				.findByActivityList(parameMap);
		context.put("detailList", detailList);
		return "detail";
	}

	public String getFootDetail() {
		String id = RequestUtil.getParam(request, "id", "0");
		HttpSession session = request.getSession();
		String lanType = "1";
		if (null != session.getAttribute("lanType")) {
			lanType = (String) session.getAttribute("lanType");
		}
		ActionContext context = ActionContext.getContext();
		Map<String, String> parameMap = new HashMap<String, String>();
		if ("2".equals(lanType)) {
			ResourceBundle boundle = ResourceBundle.getBundle("globalMessage",
					Locale.US);
			Locale local = Locale.US;
			context.setLocale(local);
		}
		parameMap.put("lanType", lanType);
		parameMap.put("id", id);
		List<SchoolPhoto> footDetail = schoolService
				.findBySchoolList(parameMap);
		context.put("detailList", footDetail);
		return "detail";
	}

	public String switchState() {
		String lanType = RequestUtil.getParam(request, "lanType", "1");
		HttpSession session = request.getSession();
		session.setAttribute("lanType", lanType);
		return information();
	}
}
